package com.interauto.Controller.casepage;

import com.interauto.bean.web.CaseinfoWeb;
import com.interauto.bean.web.RunTaskWeb;
import com.interauto.service.web.CasePageService;
import com.interauto.service.web.RunTaskPageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 任务相关的页面
 */
@Controller
@RequestMapping(value = "/task")
public class TaskHome {
    private static final Logger logger= LoggerFactory.getLogger(TaskHome.class);
    @Autowired
    private RunTaskPageService runTaskPageService;
    @Autowired
    private CasePageService casePageService;

    /**
     * 任务的主页面
     * @param projectid 要查询的项目ID
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public ModelAndView taskpagehome(@RequestParam(value = "projectid") int projectid){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("runtaskpage");
        List<RunTaskWeb> runTaskWebList=runTaskPageService.getRunTaskWebforProjectid(projectid);
        modelAndView.addObject("runTasks",runTaskWebList);
        modelAndView.addObject("projectid",projectid);
        List<CaseinfoWeb> caseinfoWebs=casePageService.getCaseinfoList(projectid);
        if(caseinfoWebs !=null && caseinfoWebs.size()>0){
            modelAndView.addObject("caseinfoWebs",caseinfoWebs);
        }
        return modelAndView;
    }
}
